<template>
  <Spin :spinning="loading" tip="Loading...">
  <div>
    <!-- 搜索 -->
    <!-- 人员仓库关系  -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType = "single"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-check" :click="enableDisable.bind()" :disabled="disableds">启用</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-close" :click="enableDisable.bind()" :disabled="disabledS">禁用</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visibleAdd" :title="'人员仓库关系维护 - 新增'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <AddForm @close="closeAdd" @save="saveAdd"></AddForm>
    </BaseDialog>
    <BaseDialog :visible.sync="visibleEdit" :title="'人员仓库关系维护 - 编辑'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <EditForm @close="closeEdit" @save="saveEdit"  :rowData="rowData" ></EditForm>
    </BaseDialog>
  </div>
  </Spin>
</template>
<script>
import { getListByPage,enableDisableById,delet} from '@/api/claim/factory/ReturnStaff';

import Vehicle from './FactoryVehicle.vue';
import AddForm from './AddForm.vue';
import EditForm from './EditForm.vue';
import importExcel from '@/pages/claimDemage/tools/importExcel.vue';
import { dictionary } from '@/utils/dictMixin';

export default {
  mixins: [dictionary],
  components: {
    Vehicle,
    AddForm,
    EditForm,
    importExcel
  },
  data() {
    return {
      disabledS: true,
      disableds: true,
      dataList: [],
      visible: false,
      visibleDrawer: false,
      showImport: false,
      collapse: true,
      rowData: {},
      infoId: null,
      exportLoading: false,
      fetchapi: getListByPage,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '配件选择',
      visibleAdd: false,
      loading: false,
      visibleEdit: false
    };
  },
  created() {

  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = true;
      this.disabledS = true;
      if (this.selectedRows.length > 0) {
        if (this.selectedRows[0].status == 55971001) {
          this.disabledS = false;
        } else {
          this.disableds = false;
        }
      } else {
        this.disableds = true;
        this.disabledS = true;
      }
      console.log("选中");
      console.log(this.selectedRows);
    },
    chooseOrderNo() {
      this.visible = true;
    },
    add() {
      this.visibleAdd = true;
    },
    edit() {
      this.visibleEdit = true;
    },
    closeAdd() {
      this.visibleAdd = false;
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    closeEdit() {
      this.visibleEdit = false;
    },
    emitFun(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    saveEdit() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    editsave(){
      this.showImport = false;
      this.fetchParams = {...this.fetchParams};
    },
    async enableDisable() {
      this.loading = true;
      this.res = await enableDisableById({id: this.selectedRows[0].relationalId});
      if (this.res != null) {
        this.loading = false;
      }
      this.fetchParams = {...this.fetchParams};
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = {...val};
      console.log(val);
    },
    // 删除
    async delFun(val) {
      this.$confirm('确定删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          this.res = await delet({id: val.relationalId});
          if (this.res.resultCode !== 200) {
            this.$notify.error({ title: '提示信息', message: res.errMsg || '删除失败!' });
          } else {
            this.$notify.success({ title: '提示信息', message: '删除成功!' });
            this.fetchParams = { ...this.fetchParams };
          }
        })
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {type: 'INPUT', label: '员工编码', fieldName: 'staffCode', placeholder: '请输入员工代码...', initialValue: ''},
        {type: 'INPUT', label: '员工账号', fieldName: 'staffId', placeholder: '请输入员工代码...', initialValue: ''},
        {type: 'INPUT', label: '员工名称', fieldName: 'staffName', placeholder: '请输入员工名称...', initialValue: ''},
        {type: 'INPUT', label: '仓库代码', fieldName: 'whCode', placeholder: '请输入仓库代码...', initialValue: ''},
        {type: 'INPUT', label: '仓库名称', fieldName: 'whName', placeholder: '请输入仓库名称...', initialValue: ''},
        {type: 'INPUT', label: '联系电话', fieldName: 'staffTel', placeholder: '请输入联系电话...', initialValue: ''},
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.emitFun(props.row)}>
                  编辑
                </multiuse-button>
                <el-divider direction="vertical" />
                <multiuse-button size="mini" type="text" onClick={() => this.delFun(props.row)}>
                  删除
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.status, '5597')}</span>;
          }
        },
        {title: '员工账号', dataIndex: 'staffId', sorter: true},
        {title: '员工编码', dataIndex: 'staffCode', sorter: true},
        {title: '员工名称', dataIndex: 'staffName', sorter: true},
        {title: '联系电话', dataIndex: 'staffTel', sorter: true},
        {title: '职位', dataIndex: 'position', sorter: true},
        {title: '仓库代码', dataIndex: 'whCode', sorter: true},
        {title: '仓库名称', dataIndex: 'whName', sorter: true},
        {title: '创建人', dataIndex: 'createdBy', sorter: true},
        {title: '创建时间', dataIndex: 'createdAt', sorter: true},
        {title: '修改人', dataIndex: 'updatedBy', sorter: true},
        {title: '修改时间', dataIndex: 'updatedAt', sorter: true}
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
